package org.dromara.comm_lhz.controller;

import lombok.AllArgsConstructor;
import org.dromara.comm_lhz.entity.AsGroupEntity;
import org.dromara.comm_lhz.service.AsGroupHService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;


/**
 * 居民社群控制器
 */
@RestController
@RequestMapping("/group")
@AllArgsConstructor
public class AsGroupHController {

    @Autowired
    private AsGroupHService asGroupHService;

    /**
     * 获取群组信息
     * @return
     */
    @GetMapping("/selGroupInfo")
    public ResponseEntity<Object> selGroupInfo(AsGroupEntity asGroupEntity, Pageable pageable) {
        return new ResponseEntity<>(asGroupHService.selGroupInfo(asGroupEntity, pageable), HttpStatus.OK);
    }

    /**
     * 根据id查询群组信息二维码
     * @param id
     * @return
     */
    @GetMapping("/selGroupInfoById")
    public ResponseEntity<Object> selGroupInfoById(Integer id) {
        return new ResponseEntity<>(asGroupHService.getById(id), HttpStatus.OK);
    }

    /**
     * 添加群组信息
     * @param asGroupEntity
     * @return
     */
    @PostMapping("/insertGroup")
    public ResponseEntity<Object> insertGroup(@RequestBody AsGroupEntity asGroupEntity) {
        return new ResponseEntity<>(asGroupHService.save(asGroupEntity), HttpStatus.OK);
    }


    /**
     * 修改群组信息
     * @param asGroupEntity
     * @return
     */
    @PostMapping("/updateGroup")
    public ResponseEntity<Object> updateGroup(@RequestBody AsGroupEntity asGroupEntity) {
        return new ResponseEntity<>(asGroupHService.updateById(asGroupEntity), HttpStatus.OK);
    }

    /**
     * 删除群组信息
     * @param id
     * @return
     */
    @GetMapping("/deleteGroup")
    public void deleteGroup(Integer id) {
        asGroupHService.removeById(id);
    }



}
